import React, {Component} from 'react';
import {base} from 'nc-lightapp-front';
const {NCRefreshBtn, NCDiv}=base;

class ProfileHead extends Component {
    static comName = 'ProfileHead';
    constructor() {
        super();
    }

    handleClick(){
        if(this.props.refreshButtonEvent){
            this.props.refreshButtonEvent();
        }
    }

    render() {
        let buttonGroup = null;
        let NonstandardButtonGroup = null;
        let headCenterCustom = null;

        const {children} = this.props;
        const {profileLayoutList, layout, ncProps} = window._ssc_gy_profile ;

        React.Children.forEach(children, (child) => {
            if (child && child.type) {
                switch (child.type.comName) { //此处获取函数名不兼容。后续处理
                    case 'ButtonGroup':
                        buttonGroup = child;
                        break;
                    case 'NonstandardButtonGroup':
                        NonstandardButtonGroup = child;
                        break;
                    case 'HeadCenterCustom':
                        headCenterCustom = child
                        break;
                    default:
                        console.warn('ProfileHead组件内，对子组件：', child, '不做处理')
                }
            }

        });

        const { createBillHeadInfo } = ncProps.BillHeadInfo;
        return (() => {
            switch(layout) {
                case profileLayoutList.treeTable:
                    return (
                        <NCDiv areaCode={NCDiv.config.HEADER}>
                        <div className="header">
                            {createBillHeadInfo({
                                title: this.props.title,
                                initShowBackBtn: false
                            })} 
                            {headCenterCustom}
                            <div className="header-right btn-group">
                                {buttonGroup}
                            </div>
                        {(this.props.refreshButtonEvent && (this.props.status != 'edit')) && <NCRefreshBtn disabled={this.props.status === 'browse' ? false : true} style={{ cursor : 'pointer'}} onClick={ this.handleClick.bind(this) }></NCRefreshBtn> }
                        </div>
                        </NCDiv>
                    );
                    break;
                case profileLayoutList.singleTable:
                    return (
                        <NCDiv areaCode={NCDiv.config.HEADER}>
                        <div className="nc-singleTable-header-area">
                            {/* 标题 title */}
                            <div className="header-title-search-area">
                               
                                {createBillHeadInfo({
                                    title: this.props.title,
                                    initShowBackBtn: this.props.backBtnClick || false,
                                    backBtnClick: this.props.backBtnClick 
                                })} 
                                {/*除了h2标题外，小组件都要外层嵌套一个div且className命名为title-search-detail，如下*/}
                                {headCenterCustom}
                            </div>
                            {/* 按钮区  btn-group */}
                            <div className="header-button-area">
                                {buttonGroup}
                                {NonstandardButtonGroup}
                            </div>
                            {(this.props.refreshButtonEvent && (this.props.status != 'edit')) && <NCRefreshBtn disabled={this.props.status === 'browse' ? false : true} style={{ cursor : 'pointer'}} onClick={ this.handleClick.bind(this) }></NCRefreshBtn> }
                        </div>
                        </NCDiv>
                    )
                    break;
            }
        })()
    }
}

export default ProfileHead
